Bug 536185 – monitor font configuration
authorBehdad Esfahbod <behdad@gnome.org>
Fri, 6 Jun 2008 16:39:37 +0000 (16:39 +0000)
committerBehdad Esfahbod <behdad@src.gnome.org>
Fri, 6 Jun 2008 16:39:37 +0000 (16:39 +0000)
2008-06-06  Behdad Esfahbod  <behdad@gnome.org>

        Bug 536185 – monitor font configuration

        * configure.in:
        * gdk/x11/gdksettings.c:
        * gtk/gtksettings.c (gtk_settings_class_init),
        (gtk_settings_notify), (settings_update_fontconfig):
        Monitor xsettings key Fontconfig/Timestamp and upon change,
        reread fontconfig configuration, clear Pango's caches, and
        redraw all widgets.

svn path=/trunk/; revision=20324

ChangeLog
configure.in
gdk/x11/gdksettings.c
gtk/gtksettings.c

index 015934280c01cc33b9b73d964b6f6ebc6f004201..722f97eedc0269601650facb68be70eb45eb1a5c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-06-06  Behdad Esfahbod  <behdad@gnome.org>
+
+       Bug 536185 – monitor font configuration
+
+       * configure.in:
+       * gdk/x11/gdksettings.c:
+       * gtk/gtksettings.c (gtk_settings_class_init),
+       (gtk_settings_notify), (settings_update_fontconfig):
+       Monitor xsettings key Fontconfig/Timestamp and upon change,
+       reread fontconfig configuration, clear Pango's caches, and
+       redraw all widgets.
+
 2008-06-06  Ross Burton  <ross@burtonini.com>
 
        * gtk/gtkwindow.c:
index f1487993de43b6760af39448e4e3b34d9fdff9fb..e11c0cdddeeb93fef46f25f8db36a211c8263875 100644 (file)
@@ -1677,6 +1677,9 @@ else
 fi
 
 GTK_PACKAGES="atk cairo gio-2.0"
+if test "x$gdktarget" = "xx11"; then
+  GTK_PACKAGES="$GTK_PACKAGES pangoft2"
+fi
 GTK_EXTRA_LIBS=
 GTK_EXTRA_CFLAGS= 
 GTK_DEP_LIBS="$GDK_EXTRA_LIBS $GTK_DEP_LIBS_FOR_X `$PKG_CONFIG --libs $GDK_PIXBUF_PACKAGES $PANGO_PACKAGES $GTK_PACKAGES_FOR_X $GTK_PACKAGES` $GTK_EXTRA_LIBS $GDK_PIXBUF_EXTRA_LIBS"
index 6ef672e2ff652eb18d1170d7725569356858dcc4..22878ab253e4374e80028510780230d8267c7715 100644 (file)
@@ -69,7 +69,8 @@ static const char gdk_settings_names[] =
   "Gtk/EnableAccels\0"        "gtk-enable-accels\0"
   "Gtk/EnableMnemonics\0"     "gtk-enable-mnemonics\0"
   "Gtk/ScrolledWindowPlacement\0" "gtk-scrolled-window-placement\0"
-  "Gtk/IMModule\0"            "gtk-im-module\0";
+  "Gtk/IMModule\0"            "gtk-im-module\0"
+  "Fontconfig/Timestamp\0"    "gtk-fontconfig-timestamp\0";
 
 
 static const struct
@@ -116,5 +117,6 @@ static const struct
   { 1326, 1343 },
   { 1361, 1381 },
   { 1402, 1430 },
-  { 1460, 1473 }
+  { 1460, 1473 },
+  { 1487, 1508 }
 };
index 3ce2046ebceb60a501b944204a233c371e3a3747..e0a6d72f98878c5be13571d4845bbce4a39e817c 100644 (file)
@@ -16,6 +16,8 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
+
 #include <config.h>
 
 #include <string.h>
@@ -30,6 +32,7 @@
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"
+#include <pango/pangofc-fontmap.h>
 #endif
 
 #define DEFAULT_TIMEOUT_INITIAL 200
@@ -108,7 +111,8 @@ enum {
   PROP_ENABLE_ACCELS,
   PROP_RECENT_FILES_LIMIT,
   PROP_IM_MODULE,
-  PROP_RECENT_FILES_MAX_AGE
+  PROP_RECENT_FILES_MAX_AGE,
+  PROP_FONTCONFIG_TIMESTAMP
 };
 
 
@@ -134,6 +138,7 @@ static void    settings_update_modules           (GtkSettings           *setting
 static void    settings_update_cursor_theme      (GtkSettings           *settings);
 static void    settings_update_resolution        (GtkSettings           *settings);
 static void    settings_update_font_options      (GtkSettings           *settings);
+static gboolean settings_update_fontconfig       (GtkSettings           *settings);
 #endif
 static void    settings_update_color_scheme      (GtkSettings *settings);
 
@@ -841,6 +846,17 @@ gtk_settings_class_init (GtkSettingsClass *class)
                                                               GTK_PARAM_READWRITE),
                                             NULL);
   g_assert (result == PROP_RECENT_FILES_MAX_AGE);
+
+  result = settings_install_property_parser (class,
+                                            g_param_spec_int ("gtk-fontconfig-timestamp",
+                                                              P_("Fontconfig configuration timestamp"),
+                                                              P_("Timestamp of current fontconfig configuration"),
+                                                              G_MININT, G_MAXINT, 0,
+                                                              GTK_PARAM_READWRITE),
+                                            NULL);
+  
+  g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
+  
 }
 
 static void
@@ -1054,6 +1070,10 @@ gtk_settings_notify (GObject    *object,
       settings_update_font_options (settings);
       gtk_rc_reset_styles (GTK_SETTINGS (object));
       break;
+    case PROP_FONTCONFIG_TIMESTAMP:
+      if (settings_update_fontconfig (settings))
+       gtk_rc_reset_styles (GTK_SETTINGS (object));
+      break;
     case PROP_CURSOR_THEME_NAME:
     case PROP_CURSOR_THEME_SIZE:
       settings_update_cursor_theme (settings);
@@ -1951,6 +1971,43 @@ settings_update_font_options (GtkSettings *settings)
   cairo_font_options_destroy (options);
 }
 
+#ifdef GDK_WINDOWING_X11
+static gboolean
+settings_update_fontconfig (GtkSettings *settings)
+{
+  static guint    last_update_timestamp;
+  static gboolean last_update_needed;
+
+  gint timestamp;
+
+  g_object_get (settings,
+               "gtk-fontconfig-timestamp", &timestamp,
+               NULL);
+
+  /* if timestamp is the same as last_update_timestamp, we already have
+   * updated fontconig on this timestamp (another screen requested it perhaps?),
+   * just return the cached result.*/
+
+  if (timestamp != last_update_timestamp)
+    {
+      PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
+      gboolean update_needed = FALSE;
+
+      if (PANGO_IS_FC_FONT_MAP (fontmap) &&
+         !FcConfigUptoDate (NULL) && FcInitReinitialize ())
+       {
+         update_needed = TRUE;
+         pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
+       }
+
+      last_update_timestamp = timestamp;
+      last_update_needed = update_needed;
+    }
+
+  return last_update_needed;
+}
+#endif /* GDK_WINDOWING_X11 */
+
 static void
 settings_update_resolution (GtkSettings *settings)
 {